{extend name="common/main"}

{block name="css"}
<!--<link href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">-->
<link rel="stylesheet" href="/static/assets/css/bootstrap.min.css" />
<link href="https://cdn.staticfile.org/font-awesome/4.4.0/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<link rel="stylesheet" href="/static/jsTree/style.min.css"/>
<style>
    .jstree-open > .jstree-anchor > .fa-folder:before {
        content: "\f07c"
    }

    .jstree-default .jstree-icon.none {
        width: 0
    }
    .ad{
        padding: .2em 1em;
        float: right;
    }
    .we{
        padding: .2em 1em;
    }
    .tr{
        margin: 15px;
    }
    .td{
        padding-top: 20px;
        padding-left: 20px;
    }
    .la{
        width:33.333%;
    }
    .am-tabs-default .am-tabs-nav a{
        line-height: 33px;
    }
    .lai{
        float: none;
        display:inline-block;
    }
    .as{
        min-height:665px;
        /*height: 665px;*/
    }
    .adf{
        display: inline-block;
    }
</style>
{/block}

{block name="body"}
<body data-type="widgets">
{include file="common/index"}
<div class="tpl-content-wrapper">
    <div class="row-content am-cf">
        <!--客户-->
        <div class="row">
            <div class="am-u-sm-4 am-u-md-4 am-u-lg-4">
                <div class="widget am-cf as">
                    <div class="widget-head am-cf">
                        <div class="widget-title  am-cf">全部客户
                            {if $Think.session.user.type==1}
                                {if $type==1}
                                <button type="button" class="am-btn am-btn-primary am-radius ad clor" id="add">新增</button>
                            {/if}
                            {/if}
                        </div>

                    </div>

                    <div class="col-sm-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-content">
                                <!--无限目录  用户 -->
                                <div id="jstree1">
                                    <ul>
                                                {$menu}
                                    </ul>
                                </div>
                                <!--/无限目录  用户 -->
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <!--用户信息-->
        <div class="row">
            <div class="am-u-sm-8 am-u-md-8 am-u-lg-8">
                <!--<h3 class="widget-title  am-cf">用户信息</h3>-->
                <div class="widget am-cf">
                    <div class="widget-head am-cf">
                        <div class="widget-title  am-cf">用户信息
                    </div>
                    </div>
                    <div class="mod_box di">
                        <div id="slectCustMsge" class="bd profile">
                            <table cellpadding="0" cellspacing="0">
                                <tbody>
                                <tr class="tr">
                                    <td class="td"><label>登陆账号：</label><span id="login_name">{$res.phone}</span></td>
                                    <td class="td"><label>用户昵称：</label><span id="grade">{$res.nickname}</span></td>
                                    <td class="td"><label>设备数量：</label><span id="selfNum">{$count}</span></td>
                                </tr>
                                <tr class="tr">
                                    <td class="td">

                                        <button type="button" class="am-btn am-btn-primary am-radius clor" onclick="denglu()" >登陆</button>
                                    </td>
                                </tr>
                                </tbody></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--设备-->
        <div class="row">
            <div class="am-u-sm-8 am-u-md-8 am-u-lg-8">
                <div data-am-widget="tabs" class="am-tabs am-tabs-default la">
                    <ul class="am-tabs-nav am-cf">
                        <li class="{if $int eq 1}am-active{/if}" data_v="1"><a href="[data-tab-panel-0]">设备</a></li>
                        {if $Think.session.user.type==1}

                        <li class="{if $int eq 2}am-active{/if}"  data_v="2"><a href="[data-tab-panel-1]">下级客户</a></li>
                        {/if}

                        <li class="{if $int eq 3}am-active{/if}"  data_v="3"><a href="[data-tab-panel-2]">资料</a></li>
                    </ul>
                </div>


                <div data-tab-panel-0 class="am-tab-panel am-active" {if $int neq 1}style="display: none"{/if}>
                    <!--设备-->
                    <div class="widget am-cf">
                    <!--<button type="button" class="am-btn am-btn-primary am-radius we clor">批量更新到期时间</button>-->
                    <!--<button type="button" class="am-btn am-btn-primary am-radius ad"> <i class="am-icon-arrow-down"></i>Excel</button>-->
                        <!--<a href="{:url('User/export')}?user_id={$user_id}" data-toggle="tooltip" title="" class="am-btn am-btn-primary am-radius ad clor">导出Excel</a>-->
                    <div class="widget-body  am-fr">
                        <div class="am-u-sm-12">
                            <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r1">
                                <thead>
                                <tr>
                                    <!--<th><input type="checkbox" id="chkClkDevices" ></th>-->
                                    <th>设备昵称</th>
                                    <th>设备号(IMEI)</th>
                                    <th>绑定账号</th>
                                    <th>激活时间</th>
                                    <th>到期时间</th>
                                    <!--<th>操作</th>-->
                                </tr>
                                </thead>
                                <tbody>
                                {foreach name="kehu" key="key" item="v"}
                                <tr class="gradeX">
                                    <!--<td><input type="checkbox" name="id_val"  value="{$v.id}"></td>-->
                                    <td>{$v.nickname}</td>
                                    <td>{$v.name}</td>
                                    <td>{$v.phone}</td>
                                    <td>{$v.add_time|date='Y-m-d H:i',###}</td>
                                    <td>{$v.expire_time|date='Y-m-d H:i',###}</td>
                                    <!--<td>-->
                                        <!--<div class="tpl-table-black-operation">-->
                                            <!--<a href="{:url('User/editkehuo')}?id={$v.id}">-->
                                                <!--<i class="am-icon-pencil"></i> 修改-->
                                            <!--</a>-->
                                            <!--&lt;!&ndash;<button type="button" style="color: #e7505a;background-color: white;padding: 5px 6px;font-size: 12px;line-height: 12px;border: 1px solid #e7505a;" class="tpl-table-black-operation-del " data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0, width: 400, height: 225}">到期时间</button>&ndash;&gt;-->
                                        <!--</div>-->
                                    <!--</td>-->
                                </tr>
                                {/foreach}
                                </tbody>
                            </table>

                                <div class="col-md-7 pull-right">
                                    {$kehu->render()}
                                </div>

                        </div>
                    </div>
                </div>
                </div>
                <div data-tab-panel-1 class="am-tab-panel am-active"{if $int neq 2}style="display: none"{/if}>
                    <!--下级客户-->
                    <div class="widget am-cf">
                        <button type="button" class="am-btn am-btn-primary am-radius we clor" id="zhuan">批量转移客户</button>
                    <div class="widget-body  am-fr">
                        <div class="am-u-sm-12">
                            <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" id="chkClkDevices" ></th>
                                    <th>客户昵称</th>
                                    <th>登录名</th>
                                    <th>类型</th>
                                    <th>性别</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {foreach name="list" key="key" item="v"}
                                <tr class="gradeX">
                                    <td>
                                        {if $v.type eq 0}
                                        <input type="checkbox" name="id_val"  value="{$v.id}"></td>
                                        {/if}
                                    <td>{$v.name}</td>
                                    <td>{$v.phone}</td>
                                    <td>{if $v.type eq 1}管理员{else}用户{/if}</td>
                                    <td>{if $v.sex eq 1}男{else}女{/if}</td>
                                    <td>
                                        <div class="tpl-table-black-operation">
                                            <a href="{:url('User/edituser')}?user_id={$v.user_id}">
                                                <i class="am-icon-pencil"></i> 修改
                                            </a>
                                            <a href="javascript:;" onclick="master_del({$v.mid},{$v.user_id})" class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {/foreach}
                                </tbody>
                            </table>
                            <div class="col-md-7 pull-right">
                                {$list->render()}
                            </div>
                        </div>
                    </div>
                </div>
                </div>
                <div data-tab-panel-2 class="am-tab-panel am-active"{if $int neq 3}style="display: none"{/if}>
                <!--资料-->
                    <div class="widget am-cf">
                <div class="widget-body am-fr">

                    <form class="am-form tpl-form-border-form tpl-form-border-br "  form="submit" id="form">

                        <div class="am-form-group">
                            <label for="user-weibo" class="am-u-sm-2">名称: </label>
                            <div class="am-u-sm-3 lai" >
                                <input type="text" name="nickname" id="user-weibo" value="{$res.name}">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="user-weibo" class="am-u-sm-2">登陆账号:</label>
                            <div class="am-u-sm-3 lai" >
                                <input type="text" name="user_name" disabled="true" value="{$res.phone}">
                                <input type="hidden" name="id" value="{$res.id}">
                            </div>
                        </div>


                        <div class="am-form-group">
                            <label for="user-weibo" class="am-u-sm-2">新密码: </label>
                            <div class="am-u-sm-3 lai" >
                                <input type="text" name="password" value="" >
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="user-weibo" class="am-u-sm-2">确认密码: </label>
                            <div class="am-u-sm-3 lai" >
                                <input type="text" name="passworder" value=""  >
                            </div>
                        </div>
                        <button type="button" class="am-btn am-btn-primary am-radius ad clor" onclick="roleSubmit()">确定</button>
                    </form>
                </div>
                </div>
                </div>
            </div>



</body>
{/block}
{block name="js"}
<script>
    $(function () {

        //信息切换
        $(".am-tabs-nav li").click(function () {
            $a= $(this).children("a").attr("href");
            $(".am-tab-panel").css("display",'none');
            $($a).css("display",'block');

        })
        //全选，全不选
        $("#chkClkDevices").change(function () {
            $a= $(this).is(':checked');
            if ($a) {
                $("input[type='checkbox']").prop("checked",'checked');
            }else {
                $("input[type='checkbox']").prop("checked", false);
            }

        })
    });
    $(document).ready(function () {
        $("#jstree1").jstree({
            "core": {"check_callback": true},
            "plugins": ["types"],
            "types": {
                "default": {"icon": "fa fa-user-secret"},
                "img": {"icon": "fa fa-user"},
            }
        });

        $('#jstree1 .jstree-anchor').on('click', function (e, data) {
//            console.log($(this).html());
            menu_id=$(this).parent().attr("menu_id"); //用户名称id
            int =$('.am-active').attr('data_v'); //状态选订
            var f=document.createElement('form');
            f.style.display='none';
            f.action='{:url("User/menu")}';
            f.method='post';
            f.innerHTML='<input type="hidden" name="menu_id" value="'+menu_id+'"/><input type="hidden" name="int" value="'+int+'"/>';
            document.body.appendChild(f);
            f.submit();
            });

//       // 新增用户
        $('#add').on('click',function () {
            menu_id=$('.jstree-clicked').parent('li').attr("menu_id");
            window.location.href="{:url('User/adduser')}?menu_id="+menu_id;
        })
        //批量转移客户
        $('#zhuan').on('click',function () {
            menu_id=$('.jstree-clicked').parent('li').attr("menu_id");
            var test_list = [];
            $("[name=id_val]:checked").each(function () {
                test_list.push($(this).val())
            });
            window.location.href="{:url('User/transfer')}?menu_id="+menu_id+"&test_list="+test_list;
        })


        });
    //切换用户
    function denglu() {
        $user_name =$('#login_name').text();
        window.location.href="{:url('Map/map')}?user_name="+$user_name;
    }
    //提交
    function roleSubmit() {
        var form = document.getElementById("form");
        var formData = new FormData(form);
        $.ajax({
            url: "{:Url('User/editzl')}",
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据
            success: function (res) {
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 2});
                    return false;
                }
                layer.msg(res.msg, {shade: 0.5, time: 800, icon: 1}, function () {
                    window.location.reload();
                });
            }
        });
    }
    //删除下级客户
    function master_del(mid ,user_id){
        layer.confirm('确认要删除该用户吗？', {btn: ["确定", "取消"], shade: 0.5}, function(index){

            $.post("{:url('User/delete')}", {mid:mid,user_id:user_id}, function(ret){
                if(ret.code != 200){
                    layer.msg(ret.msg, {icon: 2});
                    return false;
                }
                layer.msg(ret.msg, {icon: 1,time: 1500}, function(){
                    window.location.reload();
                    return false;
                });
            });
        });
        return false;
    }
</script>

<script src="http://cdn.bootcss.com/amazeui/2.7.2/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.datatables.min.js"></script>
<script src="/static/assets/js/dataTables.responsive.min.js"></script>
<!--<script src="/static/assets/js/app.js"></script>-->
<script src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
 <script src="/static/jsTree/content.min.js"></script>
 <script src="/static/jsTree/jsTree.min.js"></script>


{/block}